/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function confirmDelete(userId, userFirstname) {       
        
    $.get('../GetMessage',
            {mesId:"001"},
            function(responseData) {       
                //alert(responseData);
                $(responseData).find('Messenger').each(function(){                    
                    var MesId = $(this).find('Message').find('MesId').text();
                    var MesType = $(this).find('Message').find('MesType').text();
                    var MesDetail = $(this).find('Message').find('MesDetail').text();
                    //alert('MesId = '+MesId+' MesType = '+MesType+' MesDetail = '+MesDetail);                                       
                    
                    var result = confirm(MesDetail + ": " + userFirstname);
                    if (result == true) {
                        location.href = "UserDelete?userId="+userId;
                    }                     
                });
            }
    );                
}

function reqDivAndDep() {
    
    var dateNow = new Date();  
    
    var comId = $("#ddlCom").val();
        
    if(comId != "") {
        
        $.get('UserReqDivAndDep',
            {comId: comId, dateNow: dateNow.getMilliseconds()},
            function(responseData) {       
                //alert("responseData = " + responseData);
                // Clear combobox                
                var ddlDivOption = document.getElementById("ddlDiv");
                var ddlDepOption = document.getElementById("ddlDep");
                ddlDivOption.options.length = 1;
                ddlDepOption.options.length = 1;                

                $(responseData).find('Messenger').each(function(){                    

                    var numDiviRecCont = $(this).find('DivisionData').attr('NumRecData');
                    var numDepRecCont = $(this).find('DepartmentData').attr('NumRecData');
                    //alert('numDiviRecCont = ' + numDiviRecCont + ' numDepRecCont = ' + numDepRecCont);                                        
                                        
                    if(numDiviRecCont != 0) {
                        $(this).find('Division').each(function(){
                            var diviId = $(this).find('Id').text();
                            var diviName = $(this).find('Name').text();                                                   
                            //alert('diviId = '+diviId+' diviName = '+diviName);
                            var op = new Option( diviName , diviId );
                            ddlDivOption.options.add(op);
                        });
                    }
                    
                    if(numDepRecCont != 0) {
                        $(this).find('Department').each(function(){
                            var depId = $(this).find('Id').text();
                            var depName = $(this).find('Name').text();                                                   
                            //alert('depId = '+depId+' depName = '+depName);
                            var op = new Option( depName , depId );
                            ddlDepOption.options.add(op);
                        });
                    }
                    
                });                  
            }        
        );        
        
    } else {
        // Clear combobox                
        var ddlDivOption = document.getElementById("ddlDiv");
        var ddlDepOption = document.getElementById("ddlDep");
        ddlDivOption.options.length = 1;
        ddlDepOption.options.length = 1;
    }        
}
